// 监听
chrome.runtime.onMessage.addListener(function (message) {
  chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
    // 判断当前页面是否URL是否正确
    let currentWindowUrl = tabs[0].url
    let str=new RegExp("http")
    let flag = str.test(currentWindowUrl)
    if (flag) {
      if(message.type === 'currentPage') {
        message.value = currentWindowUrl
      }
      chrome.tabs.sendMessage(tabs[0].id, message)
    } else {
      chrome.notifications.create({
        type: "basic",
        title: "error",
        message: '当前页面的URL有误,请输入正确的url～',
        iconUrl: `../images/failure.png`
      })
      // 将页面url处理成正确-浏览器url重定向
    }
  })
})

